package com.zzyl.controller;

import com.zzyl.base.PageResponse;
import com.zzyl.base.ResponseResult;
import com.zzyl.dto.NursingProjectDto;
import com.zzyl.service.NursingProjectService;
import com.zzyl.vo.NursingProjectVo;
import io.swagger.annotations.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/*
 * 条件分页查询护理项目
 *
 *
 * */

@Api(tags = "护理项目管理")
@RestController
@RequestMapping("/nursing_project")
public class NursingProjectController extends BaseController {
    @Autowired
    private NursingProjectService nursingProjectService;

    @GetMapping
    @ApiOperation(value = "获取护理项目列表", notes = "返回护理项目列表")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "pageNum", value = "页码", dataType = "integer", paramType = "query"),
            @ApiImplicitParam(name = "pageSize", value = "每页数量", dataType = "integer", paramType = "query"),
            @ApiImplicitParam(name = "name", value = "护理项目名称", dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "status", value = "状态（0：禁用，1：启用）", dataType = "integer", paramType = "query")
    })
    public ResponseResult<PageResponse> selectByPage(Integer pageNum, Integer pageSize, String name, Integer status) {

        return success(nursingProjectService.selectByPage(pageNum, pageSize, name, status));
    }


    @PostMapping
    @ApiOperation(value = "新增护理项目")
    public ResponseResult addNursingProject(@ApiParam(value = "新增的护理项目对象", required = true) @RequestBody NursingProjectDto nursingProjectDto) {
        nursingProjectService.addNursingProject(nursingProjectDto);
        return ResponseResult.success();
    }

    @GetMapping("/{id}")
    @ApiOperation(value = "根据id查询护理项目")
    public ResponseResult<NursingProjectVo> selectById(@ApiParam(value = "护理项目对象的id", required = true) @PathVariable Long id) {
        NursingProjectVo nursingProjectVo = nursingProjectService.selectById(id);
        return success(nursingProjectVo);
    }

    @PutMapping
    @ApiOperation("修改护理项目")
    public ResponseResult updateNursingProject(@ApiParam(value = "修改的护理项目对象", required = true) @RequestBody NursingProjectDto nursingProjectDto) {
        nursingProjectService.update(nursingProjectDto);
        return success();
    }

    @DeleteMapping("/{id}")
    @ApiOperation("删除护理项目")
    public ResponseResult deleteById(@ApiParam(value = "护理项目对象的id", required = true) @PathVariable Long id) {
        nursingProjectService.deleteById(id);
        return ResponseResult.success();
    }

    @PutMapping("/{id}/status/{status}")
    @ApiOperation("更新项目状态")
    public ResponseResult updateStatus(@ApiParam(value = "护理项目对象的id", required = true) @PathVariable Long id,
                                       @ApiParam(value = "状态（0：禁用，1：启用）", required = true) @PathVariable Integer status) {
        nursingProjectService.updateStatus(id, status);
        return ResponseResult.success();
    }

    @GetMapping("/all")
    @ApiOperation("查询全部护理项目")
    public ResponseResult<List<NursingProjectVo>> getAll() {
        List<NursingProjectVo> list = nursingProjectService.queryList();
        return success(list);
    }
}
